Skip to main content
Version: 6.0.0-beta.3 - 6.0.0-beta.4

estimateEnergy

Estimate the energy required to trigger the contract. This interface requires the fullnode node to enable the service. If the call is not enabled, an error will be reported. You can continue to use the triggerconstantcontract interface to estimate the energy. (v5.1.0 new interface)

Usage

const result = await tronWeb.transactionBuilder.estimateEnergy(contractAddress, functionSelector, options, parameter, issuerAddress);

Parameters

The parameters of estimateEnergy() is same as triggerSmartContract().

Returns

{
    /**
     * The energy required for trigger the contract.
     */
    energy_required: number;
    result: {
        result: boolean;
    }
}

Example

>const result = await tronWeb.transactionBuilder.estimateEnergy(
    'TPYwAC9Y4uUcT2QH3WPPjqxzJSJWymMoMS',
    'balanceOf(address)', {}, 
    [{ type:'address',value: 'THvMiWQeVPGEMuBtAnuKn2QpuSjqjrGQGu' }]
)
> {
  "result": {
    "result": true,
  },
  "energy_required": 900000
}